﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ReflectedIEnumerable.cs" company="">
//   
// </copyright>
// <summary>
//   The reflected i enumerable.
// </summary>
// --------------------------------------------------------------------------------------------------------------------



using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Syberia.Metacode;

namespace Syberia.Client.Extensions.Metacode
{
    /// <summary>
    /// The reflected i enumerable.
    /// </summary>
    public class ReflectedIEnumerable : ExplorableObject
    {
        /// <summary>
        /// The arr.
        /// </summary>
        private readonly IEnumerable arr;

        /// <summary>
        /// Initializes a new instance of the <see cref="ReflectedIEnumerable"/> class. 
        /// Initializes a new instance of the <see cref="ReflectedIEnumerable"/> class.
        /// </summary>
        /// <param name="ie">
        /// The ie.
        /// </param>
        public ReflectedIEnumerable(IEnumerable ie)
        {
            this.arr = ie;
        }

        /// <summary>
        /// Gets Name.
        /// </summary>
        public override string Name
        {
            get
            {
                return "IEnumerable";
            }
        }

        /// <summary>
        /// Gets SubObjects.
        /// </summary>
        public override IEnumerable<ExplorableObject> SubObjects
        {
            get
            {
                int cnt = 0;
                foreach (var o in this.arr)
                {
                    string n = string.Format("[{0}]", cnt);

                    ////if ((o as INamedObject != null))
                    ////{
                    ////    try
                    ////    {
                    ////        n+=(o as INamedObject).Name;
                    ////    }
                    ////    catch{}
                    ////}
                    yield return new ReflectionExplorableObject(o, n, null);
                    cnt++;
                }
            }
        }
    }
}